package io.bdmc.modules.sys.service.impl;

import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import io.bdmc.common.utils.MyPage;
import io.bdmc.modules.sys.entity.SysDictData;
import io.bdmc.modules.sys.entity.SysDictType;
import io.bdmc.modules.sys.mapper.SysDictTypeMapper;
import io.bdmc.modules.sys.model.SysDictTypeParam;
import io.bdmc.modules.sys.service.ISysDictDataService;
import io.bdmc.modules.sys.service.ISysDictTypeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/**
 * <p>
 * 字典类型表 服务实现类
 * </p>
 *
 * @author 黄露
 * @since 2021-04-28
 */
@Service
public class SysDictTypeServiceImpl extends ServiceImpl<SysDictTypeMapper, SysDictType> implements ISysDictTypeService {
    @Autowired
    SysDictTypeMapper _sysdicttypeMapper;

    @Autowired
    ISysDictDataService dictDataMapper;

    @Override
    public MyPage<SysDictType> mySelectPage(MyPage<SysDictType> myPage, SysDictTypeParam param) {
        return _sysdicttypeMapper.mySelectPage(myPage,param);
    }

    @Transactional
    @Override
    public boolean updateDictType(SysDictType dictType) {
        SysDictType dbSysDictType = _sysdicttypeMapper.selectById(dictType.getDictId());
        if(!dbSysDictType.getDictType().equals(dictType.getDictType())){
            dictDataMapper.update(new LambdaUpdateWrapper<SysDictData>().set(SysDictData::getDictType,dictType.getDictType()).eq(SysDictData::getDictType,dbSysDictType.getDictType()));
        }
        return dictType.updateById();
    }
}
